package C9_6_ReplaceConditionalWithPolymorphism;


/**
 * @author xugang1
 * @updated 2022/7/25
 * @description 以多态取代条件表达式
 */

public class EmployeeType {



    /**
     * 重构前操作
     */
    int payAmount(Employee emp) {
        switch (getTypeCode()) {
            case ENGINEER:
                return emp.getMonthlySalary();
            case SALESMAN:
                return emp.getMonthlySalary() + emp.getCommission();
            case MANAGER:
                return emp.getMonthlySalary() + emp.getBonus();
            default:
                throw new RuntimeException("Incorrect Employee")
        }
    }

===================================================================================
    /**
     * 重构后
     */
    abstract int payAmount(Employee emp);
}
